package com.wgts.wgts.mvp.view.activity.classification;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.wgts.wgts.R;
import com.wgts.wgts.control.recycleview.CustomerGridLayoutManager;
import com.wgts.wgts.netmodle.resp.AllClassTypeEntity;
import com.wgts.wgts.netmodle.resp.ClassificationDetailEntity;
import com.wgts.wgts.netmodle.resp.ClassificationEntity;

import java.util.ArrayList;
import java.util.List;

public class ClassificationDetailAdapter extends RecyclerView.Adapter<ClassificationDetailAdapter.ClassificationDetailViewHolder>{

    private List<AllClassTypeEntity.Entity> classificationDetailEntitys;

    private Context context;

    public ClassificationDetailAdapter(List<AllClassTypeEntity.Entity> classificationDetailEntitys, Context context){
        this.classificationDetailEntitys = classificationDetailEntitys;
        this.context = context;
    }

    @NonNull
    @Override
    public ClassificationDetailViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new ClassificationDetailViewHolder(LayoutInflater.from(context).inflate(R.layout.classification_detail_item, viewGroup, false));
    }

    @Override
    public void onBindViewHolder(@NonNull ClassificationDetailViewHolder classificationDetailViewHolder, int i) {
        classificationDetailViewHolder.tvTitle.setText(classificationDetailEntitys.get(i).typeName);
        CustomerGridLayoutManager gridLayoutManager = new CustomerGridLayoutManager(context, 3);
        classificationDetailViewHolder.recyclerView.setLayoutManager(gridLayoutManager);
        classificationDetailViewHolder.recyclerView.setAdapter(new ClassificationDetailProductAdapter(context, classificationDetailEntitys.get(i).subTypes, Integer.valueOf(classificationDetailEntitys.get(i).typeId)));
    }

    @Override
    public int getItemCount() {
        return classificationDetailEntitys.size();
    }

    public class ClassificationDetailViewHolder extends RecyclerView.ViewHolder{

        public View itemView;

        public TextView tvTitle;

        public RecyclerView recyclerView;

        public ClassificationDetailViewHolder(@NonNull View itemView) {
            super(itemView);
            tvTitle = itemView.findViewById(R.id.tv_title);

            recyclerView = itemView.findViewById(R.id.recycle_class_product);
            this.itemView = itemView;
        }
    }
}
